﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapGASTGA(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveGASTGA(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryGASTGA(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapGASTGA(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertGASTGA(dwLocal);
            }
            UpdateGASTGA(dwLocal);
        }
        public void InsertGASTGA(DataRow dwData, string ITXDBVERSION = "50.24")
        {

            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "INSERT INTO GASTGA(GAGMANDANT, GAGART, GAGVAR, GAGFARBE, GAGPOS, GAGGART, GAGGVAR, GAGGFARBE, GAGABF, GAGKGNET, GAGKGBRUT, GAGDISPOKZ, GAGBEM, GAGFDZANZ, GAGANTEIL, GAGBASIS, GAGFILLER)"
            + " VALUES (:GAGMANDANT,:GAGART, :GAGVAR, :GAGFARBE, :GAGPOS,:GAGART, :GAGVAR, '000000    ', 200, '0001000000', '0001000000', 'B', '                    ', 1, 100000, 10000, '                                   ')";
            or1.Parameters.Add("GAGMANDANT", OracleType.NVarChar).Value = dwData["GAGMANDANT"].ToString();
            or1.Parameters.Add("GAGART", OracleType.NVarChar).Value = dwData["GAGART"].ToString();
            or1.Parameters.Add("GAGVAR", OracleType.NVarChar).Value = dwData["GAGVAR"].ToString();
            or1.Parameters.Add("GAGFARBE", OracleType.NVarChar).Value = dwData["GAGFARBE"].ToString();
            or1.Parameters.Add("GAGPOS", OracleType.NVarChar).Value = dwData["GAGPOS"].ToString();
            setResult = Connect2Proxy(or1);
        }
        public DataSet QueryGASTGA(string yart, string yvar, string ycolor)
        {
            DataSet setReturn = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM GASTGA WHERE  "
                + "  GAGMANDANT=:GAGMANDANT AND GAGART=:GAGART AND GAGVAR=:GAGVAR AND GAGFARBE=:GAGFARBE";
            or1.Parameters.Add("GAGMANDANT", OracleType.NVarChar).Value = "00";
            or1.Parameters.Add("GAGART", OracleType.NVarChar).Value = yart;
            or1.Parameters.Add("GAGVAR", OracleType.NVarChar).Value = yvar;
            or1.Parameters.Add("GAGFARBE", OracleType.NVarChar).Value = ycolor;

            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "GASTGA";
            }

            setReturn.Merge(Result);
            return setReturn;
        }
        public DataSet QueryGASTGA(string yart)
        {
            DataSet setReturn = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT GAGART,GAGVAR,GAGFARBE FROM GASTGA WHERE  "
                + "  GAGMANDANT=:GAGMANDANT AND GAGART=:GAGART";
            or1.Parameters.Add("GAGMANDANT", OracleType.NVarChar).Value = "00";
            or1.Parameters.Add("GAGART", OracleType.NVarChar).Value = yart;
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "GASTGA";
            }
            setReturn.Merge(Result);
            return setReturn;
        }
        public DataSet QueryGASTGA(DataRow dwData, int option = 1)
        {
            DataSet setReturn = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1;

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM GASTGA WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM GASTGA WHERE  "
                            + "  GAGMANDANT=:GAGMANDANT AND GAGART=:GAGART AND GAGVAR=:GAGVAR AND GAGFARBE=:GAGFARBE AND GAGPOS=:GAGPOS";
                    or1.Parameters.Add("GAGMANDANT", OracleType.NVarChar).Value = dwData["GAGMANDANT"].ToString();
                    or1.Parameters.Add("GAGART", OracleType.NVarChar).Value = dwData["GAGART"].ToString();
                    or1.Parameters.Add("GAGVAR", OracleType.NVarChar).Value = dwData["GAGVAR"].ToString();
                    or1.Parameters.Add("GAGFARBE", OracleType.NVarChar).Value = dwData["GAGFARBE"].ToString();
                    or1.Parameters.Add("GAGPOS", OracleType.NVarChar).Value = dwData["GAGPOS"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT * FROM GASTGA WHERE  "
                            + "  GAGMANDANT=:GAGMANDANT AND GAGART=:GAGART";
                    or1.Parameters.Add("GAGMANDANT", OracleType.NVarChar).Value = dwData["GAGMANDANT"].ToString();
                    or1.Parameters.Add("GAGART", OracleType.NVarChar).Value = dwData["GAGART"].ToString();
                    break;
                case 6:
                    or1.CommandText = "  SELECT GAAUFKRS,GAAUFLFD,GAAUFPOS,M.* FROM VKPOS JOIN GAAUF ON VKPSA='  ' AND VKPMANDANT=GAMANDANT AND VKPAUFKRS=GAAUFKRS AND VKPAUFLFD=GAAUFLFD AND VKPAUFPOS=GAAUFPOS AND GASA=610"
                    + " JOIN GASTGA M ON  GAGART=GAART "
                        + "WHERE VKPMANDANT=:VKPMANDANT AND VKPAUFKRS=:VKPAUFKRS AND VKPAUFLFD=:VKPAUFLFD ";
                    or1.Parameters.Add("VKPMANDANT", OracleType.NVarChar).Value = dwData["VKPMANDANT"].ToString();
                    or1.Parameters.Add("VKPAUFKRS", OracleType.NVarChar).Value = dwData["VKPAUFKRS"].ToString();
                    or1.Parameters.Add("VKPAUFLFD", OracleType.NVarChar).Value = dwData["VKPAUFLFD"].ToString();
                    break;
                case 7:
                    or1.CommandText = "  SELECT GAAUFKRS,GAAUFLFD,GAAUFPOS,M.* FROM VKPOS JOIN GAAUF ON VKPSA='  ' AND VKPMANDANT=GAMANDANT AND VKPAUFKRS=GAAUFKRS AND VKPAUFLFD=GAAUFLFD AND VKPAUFPOS=GAAUFPOS AND GASA=610"
                    + " JOIN GASTGA M ON  GAGART=GAART "
                        + "WHERE VKPMANDANT=:VKPMANDANT AND VKPAUFKRS=:VKPAUFKRS AND VKPAUFLFD=:VKPAUFLFD AND VKPAUFPOS=:VKPAUFPOS ";
                    or1.Parameters.Add("VKPMANDANT", OracleType.NVarChar).Value = dwData["VKPMANDANT"].ToString();
                    or1.Parameters.Add("VKPAUFKRS", OracleType.NVarChar).Value = dwData["VKPAUFKRS"].ToString();
                    or1.Parameters.Add("VKPAUFLFD", OracleType.NVarChar).Value = dwData["VKPAUFLFD"].ToString();
                    or1.Parameters.Add("VKPAUFPOS", OracleType.NVarChar).Value = dwData["VKPAUFPOS"].ToString();
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "GASTGA";
            }

            setReturn.Merge(Result);
            return setReturn;
        }
        public void UpdateGASTGA(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE GASTGA SET "
+ "GAGMANDANT=:GAGMANDANT,"
+ "GAGART=:GAGART,"
+ "GAGVAR=:GAGVAR,"
+ "GAGFARBE=:GAGFARBE,"
+ "GAGPOS=:GAGPOS,"
+ "GAGGART=:GAGGART,"
+ "GAGGVAR=:GAGGVAR,"
+ "GAGGFARBE=:GAGGFARBE,"
+ "GAGABF=:GAGABF,"
+ "GAGKGNET=:GAGKGNET,"
+ "GAGKGBRUT=:GAGKGBRUT,"
+ "GAGDISPOKZ=:GAGDISPOKZ,"
+ "GAGBEM=:GAGBEM,"
+ "GAGFDZANZ=:GAGFDZANZ,"
+ "GAGANTEIL=:GAGANTEIL,"
+ "GAGBASIS=:GAGBASIS,"
+ "GAGFILLER=:GAGFILLER "
                + " WHERE  "
                + "  GAGMANDANT=:GAGMANDANT AND GAGART=:GAGART  AND GAGVAR=:GAGVAR  AND GAGFARBE=:GAGFARBE AND GAGPOS=:GAGPOS";

            or1.Parameters.Add("GAGMANDANT", OracleType.NVarChar).Value = dwData["GAGMANDANT"].ToString();
            or1.Parameters.Add("GAGART", OracleType.NVarChar).Value = dwData["GAGART"].ToString();
            or1.Parameters.Add("GAGVAR", OracleType.NVarChar).Value = dwData["GAGVAR"].ToString();
            or1.Parameters.Add("GAGFARBE", OracleType.NVarChar).Value = dwData["GAGFARBE"].ToString();
            or1.Parameters.Add("GAGPOS", OracleType.NVarChar).Value = dwData["GAGPOS"].ToString();
            or1.Parameters.Add("GAGGART", OracleType.NVarChar).Value = dwData["GAGGART"].ToString();
            or1.Parameters.Add("GAGGVAR", OracleType.NVarChar).Value = dwData["GAGGVAR"].ToString();
            or1.Parameters.Add("GAGGFARBE", OracleType.NVarChar).Value = dwData["GAGGFARBE"].ToString();
            or1.Parameters.Add("GAGABF", OracleType.NVarChar).Value = dwData["GAGABF"].ToString();
            or1.Parameters.Add("GAGKGNET", OracleType.NVarChar).Value = dwData["GAGKGNET"].ToString();
            or1.Parameters.Add("GAGKGBRUT", OracleType.NVarChar).Value = dwData["GAGKGBRUT"].ToString();
            or1.Parameters.Add("GAGDISPOKZ", OracleType.NVarChar).Value = dwData["GAGDISPOKZ"].ToString();
            or1.Parameters.Add("GAGBEM", OracleType.NVarChar).Value = dwData["GAGBEM"].ToString();
            or1.Parameters.Add("GAGFDZANZ", OracleType.NVarChar).Value = dwData["GAGFDZANZ"].ToString();
            or1.Parameters.Add("GAGANTEIL", OracleType.NVarChar).Value = dwData["GAGANTEIL"].ToString();
            or1.Parameters.Add("GAGBASIS", OracleType.NVarChar).Value = dwData["GAGBASIS"].ToString();
            or1.Parameters.Add("GAGFILLER", OracleType.NVarChar).Value = dwData["GAGFILLER"].ToString();
            Connect2Proxy(or1);
        }
    }
}
